package com.bst.base.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bst.common.annotation.Log;
import org.springframework.stereotype.Controller;
import com.bst.common.enums.BusinessType;
import com.bst.base.domain.BaseDownloadLog;
import com.bst.base.service.IBaseDownloadLogService;
import com.bst.common.core.controller.BaseController;
import com.bst.common.core.domain.AjaxResult;
import com.bst.common.utils.poi.ExcelUtil;
import com.bst.common.core.page.TableDataInfo;

/**
 * 文件下载日志Controller
 * 
 * @author laoliu
 * @date 2025-02-26
 */
@Controller
@RequestMapping("/base/log")
public class BaseDownloadLogController extends BaseController
{
    private String prefix = "base/log";

    @Autowired
    private IBaseDownloadLogService baseDownloadLogService;

    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询文件下载日志列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseDownloadLog baseDownloadLog)
    {
        startPage();
        List<BaseDownloadLog> list = baseDownloadLogService.selectBaseDownloadLogList(baseDownloadLog);
        return getDataTable(list);
    }

    /**
     * 导出文件下载日志列表
     */
    @Log(title = "文件下载日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseDownloadLog baseDownloadLog)
    {
        List<BaseDownloadLog> list = baseDownloadLogService.selectBaseDownloadLogList(baseDownloadLog);
        ExcelUtil<BaseDownloadLog> util = new ExcelUtil<BaseDownloadLog>(BaseDownloadLog.class);
        return util.exportExcel(list, "文件下载日志数据");
    }

    /**
     * 新增文件下载日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文件下载日志
     */
    @Log(title = "文件下载日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseDownloadLog baseDownloadLog)
    {
        return toAjax(baseDownloadLogService.insertBaseDownloadLog(baseDownloadLog));
    }

    /**
     * 修改文件下载日志
     */
    @GetMapping("/edit/{idDownloadLog}")
    public String edit(@PathVariable("idDownloadLog") Long idDownloadLog, ModelMap mmap)
    {
        BaseDownloadLog baseDownloadLog = baseDownloadLogService.selectBaseDownloadLogByIdDownloadLog(idDownloadLog);
        mmap.put("baseDownloadLog", baseDownloadLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存文件下载日志
     */
    @Log(title = "文件下载日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseDownloadLog baseDownloadLog)
    {
        return toAjax(baseDownloadLogService.updateBaseDownloadLog(baseDownloadLog));
    }

    /**
     * 删除文件下载日志
     */
    @Log(title = "文件下载日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseDownloadLogService.deleteBaseDownloadLogByIdDownloadLogs(ids));
    }
}
